/*
 * 自定义button
 */
package com.res0w.SMMS.ui.UDResource;

import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author res0w
 * @since 2009-9-24
 * @version 0.2
 */
public class ImageButton extends JButton {

    public ImageButton() {
        ImageIcon defaultIcon = new ImageIcon(
                getClass().getResource("/com/res0w/SMMS/ui/UDResource/button_default.png"));
        ImageIcon hoverIcon = new ImageIcon(
                getClass().getResource("/com/res0w/SMMS/ui/UDResource/button_hover.png"));
        ImageIcon pressedIcon = new ImageIcon(
                getClass().getResource("/com/res0w/SMMS/ui/UDResource/button_hover.png"));
        IButtonSet(defaultIcon, hoverIcon, pressedIcon);
    }
 public ImageButton(String defaultIcon, String hoverIcon,
            String pressedIcon) {
        ImageIcon defau = new ImageIcon(
                getClass().getResource(defaultIcon));
        ImageIcon hover = new ImageIcon(
                getClass().getResource(hoverIcon));
        ImageIcon press = new ImageIcon(
                getClass().getResource(pressedIcon));
        IButtonSet(defau, hover, press);
    }

    private void IButtonSet(ImageIcon defaultIcon, ImageIcon hoverIcon,
            ImageIcon pressedIcon) {
        setSize(new Dimension(defaultIcon.getIconWidth(),
                defaultIcon.getIconHeight()));
        setIcon(defaultIcon);
//        setMargin(new Insets(0, 0, 0, 0));
        setIconTextGap(0);
        setBorderPainted(false);
        setText(null);
        setRolloverEnabled(true);
        setBounds(0, 0, 0, 0);
        this.setPressedIcon(pressedIcon);
        this.setRolloverIcon(hoverIcon);
    }
}
